using System;
using bitzhuwei.Compiler;

namespace bitzhuwei.AnsiCFormat {
    /// <summary>
    /// Correspond to the Vn node labeled_statement in the grammar(AnsiC).
    /// </summary>
    internal partial class Vnlabeled_statement : IFullFormat {
        // [178] labeled_statement = 'identifier' ':' statement ;
        // [179] labeled_statement = 'case' constant_expression ':' statement ;
        // [180] labeled_statement = 'default' ':' statement ;


        private readonly IFullFormat complex;

        private readonly TokenRange _scope;
        public TokenRange Scope => _scope;
        public void FullFormat(BlankConfig? preConfig, TextWriter writer, FormatContext context) {
            context.PrintBlanksAnd(this.complex, preConfig, writer);
        }


        // [178] labeled_statement = 'identifier' ':' statement ;
        public Vnlabeled_statement(Token r2, Token r1, Vnstatement r0) {
            this.complex = new complex0(r2, r1, r0);
            this._scope = new TokenRange(r2, r0);
        }
        class complex0 : IFullFormat {
            private readonly TokenRange _scope;
            public TokenRange Scope => _scope;
            public void FullFormat(BlankConfig? preConfig, TextWriter writer, FormatContext context) {
                var config = new BlankConfig();
                context.PrintBlanksAnd(r2, preConfig, writer);
                context.PrintCommentsBetween(r2, r1, config, writer);
                context.PrintBlanksAnd(r1, config, writer);
                context.PrintCommentsBetween(r1, r0, config, writer);
                context.PrintBlanksAnd(r0, config, writer);
            }
            public readonly Token r2;
            public readonly Token r1;
            public readonly Vnstatement r0;
            public complex0(Token r2, Token r1, Vnstatement r0) {
                this.r2 = r2;
                this.r1 = r1;
                this.r0 = r0;
                this._scope = new TokenRange(r2, r0);
            }
        }

        // [179] labeled_statement = 'case' constant_expression ':' statement ;
        public Vnlabeled_statement(Token r3, Vnconstant_expression r2, Token r1, Vnstatement r0) {
            this.complex = new complex1(r3, r2, r1, r0);
            this._scope = new TokenRange(r3, r0);
        }
        class complex1 : IFullFormat {
            private readonly TokenRange _scope;
            public TokenRange Scope => _scope;
            public void FullFormat(BlankConfig? preConfig, TextWriter writer, FormatContext context) {
                var config = new BlankConfig();
                context.PrintBlanksAnd(r3, preConfig, writer);
                context.PrintCommentsBetween(r3, r2, config, writer);
                context.PrintBlanksAnd(r2, config, writer);
                context.PrintCommentsBetween(r2, r1, config, writer);
                context.PrintBlanksAnd(r1, config, writer);
                context.PrintCommentsBetween(r1, r0, config, writer);
                context.PrintBlanksAnd(r0, config, writer);
            }
            public readonly Token r3;
            public readonly Vnconstant_expression r2;
            public readonly Token r1;
            public readonly Vnstatement r0;
            public complex1(Token r3, Vnconstant_expression r2, Token r1, Vnstatement r0) {
                this.r3 = r3;
                this.r2 = r2;
                this.r1 = r1;
                this.r0 = r0;
                this._scope = new TokenRange(r3, r0);
            }
        }

        // [180] labeled_statement = 'default' ':' statement ;
        // complex2 repeated with complex0



    }
}
